#!/bin/awk -f
### taks file "tham" (result of thfit) and loads the energies
### into the decoration file ARGV[1]
BEGIN{
  fn="tham";
  while(getline<fn){if($1 == "coef"){e[$4]=$3}};
  close(fn);
  print "## decofile obtained from "ARGV[1]" and tham";
  print "";
}
$1~/ *def/{print $0}
$0!~/ *\#/&&$0!~/ *\n/{
  if($1~/^ *\\obj/&&e[$2]!=""){print "";obj=$2; eth=0};
  if(obj!=""){
    if($1~/^ *\\tham/){objs=objs" \\tham "e[obj]"\n"}else{objs=objs""$0"\n"}
  }
  if($1~/^ *\\endobj/&&obj!=""){printf objs;objs="";obj=""};
}
END{
}
